/**
 * 定义站点地图模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.bcSendPlatformDataStrategy.bcSendPlatformDataStrategyManager', [
	                                                                       'water.entity.bcSendPlatformDataStrategy',
	                                                                       'water.entity.processStrategy',
	                                                                       'water.entity.strategy']);
		
	module.controller('bcSendPlatformDataStrategyManagerController',function($scope,$state,$stateParams,
			$bcSendPlatformDataStrategyService,$strategyService,$processStrategyService){

		/**
		 * 传过来的平台ID
		 */
		$scope.platformId = $stateParams.platformId;
		
		/**
		 * 对应平台的策略
		 */
		$scope.list;
		
		/**
		 * 系统中所有的存储策略
		 */
		$scope.strategyList;
		
		/**
		 * 系统中所有数据解析的策略
		 */
		$scope.processStrategyList;
		
		/**
		 * 返回按钮点击事件
		 */
		$scope.onGoBackClick = function(){
			$state.go("bcSendPlatform");
		}
		
		/**
		 * 获取对应平台的数据策略
		 */
		$scope.getList = function(){
			$bcSendPlatformDataStrategyService.getList($scope.platformId).then(function(data){
				$scope.list = data;
			});
		}
		
		/**
		 * 获取对应平台的数据策略
		 */
		$scope.getStrategyList = function(){
			$strategyService.getList().then(function(data){
				
				var temp = [];
				
				for(var i=0;i<data.length;i++){
					temp.push({
						k:data[i].strategyId,
						v:data[i].strategyName
					});
				}
				
				$scope.strategyList = temp;
			});
		}
		
		/**
		 * 获取对应平台的解析策略
		 */
		$scope.getProcessStrategyList = function(){
			$processStrategyService.getList().then(function(data){
				
				var temp = [];
				
				for(var i=0;i<data.length;i++){
					temp.push({
						k:data[i].strategyId,
						v:data[i].strategyName
					});
				}
				
				console.log(temp);
				
				$scope.processStrategyList = temp;
			});
		}
		
		/**
		 * 添加参数按钮点击事件
		 */
		$scope.onAddClick = function(){
			$scope.list.push({
				PLATFORM_ID:$scope.platformId
			});
		}
		
		/**
		 * 保存点击事件
		 */
		$scope.onCreateClick = function(model){
			$bcSendPlatformDataStrategyService.create(model).then(function(){
				alert("保存成功");
				$scope.getList();
			}).catch(function(error){
				alert(error);
			});
		}
		
		/**
		 * 修改点击事件
		 */
		$scope.onUpdateClick = function(model){
			$bcSendPlatformDataStrategyService.update(model).then(function(){
				alert("保存成功");
				$scope.getList();
			}).catch(function(error){
				alert(error);
			});
		}
		
		/**
		 * 修改点击事件
		 */
		$scope.onDeleteClick = function(model){
			$bcSendPlatformDataStrategyService.deleteModel(model.ID).then(function(){
				$scope.getList();
			});
		}
		
		$scope._init = function(){
			$scope.getProcessStrategyList();
			$scope.getStrategyList();
			$scope.getList();
		}
		
		$scope._init();
	});
	
}(window, angular));


